cmake_minimum_required(VERSION 3.10)
project(learn-deep-learning)

# 设置 macOS 特定配置
if(APPLE)
    # 手动设置 OpenMP 路径（Homebrew 安装位置）
    set(OPENMP_ROOT "/usr/local/opt/libomp")
    
    # 手动指定包含路径和库路径
    set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Xpreprocessor -fopenmp -I${OPENMP_ROOT}/include")
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Xpreprocessor -fopenmp -I${OPENMP_ROOT}/include")
    
    # 查找 OpenMP 库
    find_library(OPENMP_LIBRARY
        NAMES omp libomp.dylib
        PATHS ${OPENMP_ROOT}/lib
        NO_DEFAULT_PATH
    )
    
    if(OPENMP_LIBRARY)
        message(STATUS "Found libomp: ${OPENMP_LIBRARY}")
        add_library(OpenMP::OpenMP_C IMPORTED INTERFACE)
        set_property(TARGET OpenMP::OpenMP_C PROPERTY
            INTERFACE_LINK_LIBRARIES ${OPENMP_LIBRARY})
    else()
        message(WARNING "libomp not found at ${OPENMP_ROOT}/lib")
    endif()
endif()

# 设置C++标准
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

# 全局设置
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)

# 启用优化
if(NOT CMAKE_BUILD_TYPE STREQUAL "Debug")
    add_compile_options(-O3 -march=native)
else()
    add_compile_options(-g)
endif()

# 查找依赖
find_package(TBB REQUIRED)
find_package(Eigen3 REQUIRED)
find_package(OpenMP REQUIRED)


# 添加子目录
add_subdirectory(lib)
add_subdirectory(app)
add_subdirectory(test)

# 安装配置
install(DIRECTORY data/FashionMnist/ DESTINATION share/data/FashionMnist)